package com.qf.limit.service.impl;

import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.limit.commons.utils.UserUtils;
import com.qf.limit.dao.FriendrelationDao;
import com.qf.limit.entity.Friendrelation;
import com.qf.limit.entity.vo.FriendVo;
import com.qf.limit.service.FriendrelationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Friendrelation)表服务实现类
 *
 * @author makejava
 * @since 2024-09-13 12:48:10
 */
@Service("friendrelationService")
public class FriendrelationServiceImpl extends ServiceImpl<FriendrelationDao, Friendrelation> implements FriendrelationService {


    @Override
    public boolean isFriendRelation(Integer uid, Integer fid) {
        return this.query()
                .eq("uid",uid)
                .eq("fid",fid)
                .count()>0;
    }

    @Override
    public int addFriendRelation(Integer uid, Integer fid, String beizhu1, String beizhu2) {
        Friendrelation friendrelation1 = new Friendrelation()
                .setUid(fid)
                .setFid(uid)
                .setBeizhu(beizhu2);
        Friendrelation friendrelation2 = new Friendrelation()
                .setUid(uid)
                .setFid(fid)
                .setBeizhu(beizhu1);

        return getBaseMapper().insertBatch(ListUtil.of(friendrelation1,friendrelation2));
    }

    @Override
    public List<FriendVo> queryMyFriend() {
        //获取当前用户id
        Integer uid = UserUtils.getUid();
        //查询当前用户的好友列表
        return getBaseMapper().queryMyFriend(uid);
    }
}

